package tools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class DeletebyID {
	private static Connection connection;
	private static Statement stat;
	
	public static void deleteEvent(String id){
		connection = createConnection.connect();
		
		try {
			stat = connection.createStatement();
			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");
			
			PreparedStatement prepst = connection.prepareStatement("DELETE FROM `sopra-ws12-awesome_fireballs`.`Events` WHERE `idEvents`=?;");
			
			connection.setAutoCommit(false);
			
			prepst.setString(1, id);
			prepst.addBatch();
			prepst.executeBatch();
			
			connection.setAutoCommit(true);
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void deleteTask(String id){
		createConnection.connect();
		
		try {
			stat = connection.createStatement();
			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");
			
			PreparedStatement prepst = connection.prepareStatement("DELETE FROM `sopra-ws12-awesome_fireballs`.`Task` WHERE `idTask`=?;");
			
			connection.setAutoCommit(false);
			
			prepst.setString(1, id);
			prepst.addBatch();
			prepst.executeBatch();
			
			connection.setAutoCommit(true);
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
}
